<template>
  <div>
    <header-comm></header-comm>
    <div class="bcg">
      <div class="xw_box">
        <a-button type="primary" @click="addnewgg">添加分类</a-button>
        <a-table :pagination='pagination' :columns="columns" @change="getadclassList" :data-source="data">
          <template slot="operation" slot-scope="text, record, index">
            <div class="editable-row-operations">
              <a href="javascript:;" @click="edit(record)" class="del">修改</a>
              <a-popconfirm title="确定删除吗?" class="del" @confirm="() => ggfldelete(record.id_num)">
                <a href="javascript:;">删除</a>
              </a-popconfirm>
            </div>
          </template>
        </a-table>
      </div>
      <div class="gg_tk" v-if="gg_flag">
        <addggfl></addggfl>

      </div>

    </div>
  </div>
</template>

<script>
import headerComm from "../header-comm/header.vue";
import addggfl from "./add_ggfl.vue";
const columns = [
  {
    title: "ID",
    dataIndex: "id_num",
    key: "id_num"
  },
  {
    title: "广告编号",
    dataIndex: "number",
    key: "number",
  },
  {
    title: "分类描述",
    dataIndex: "describe",
    key: "describe"
  },
  {
    title: "操作",
    dataIndex: "operation",
    key: "operation",
    scopedSlots: { customRender: "operation" }
  }
];


import qs from "qs";

export default {
  inject: ["reload"],
  data() {
    return {
      data:[],
      columns,
      editval:'',
      edittit:'新增',
      gg_flag:false,
       pagination:{
         defaultPageSize: 10,
        showTotal: total => `共 ${total} 条数据`,
        total: 0,
        current:1
      }
    };
  },

  methods: {
    ggfldelete(id_num) {
      this.axios.post("suggest/adclassDelete.php",qs.stringify({
        id_num:id_num
      })).then(res=>{
        console.log(res)
          if (res.data.code == 303) {
            this.$notification["success"]({
              message: "成功",
              description: res.data.msg
            });
               this.getadclassList();
          } else {
            
            this.$notification["error"]({
              message: "失败",
              description: res.data.msg
            });
          }
      })
    },
    edit(value) {
      this.editval=value
        this.gg_flag=true
        this.edittit='修改'

    },
    addnewgg(){
        this.gg_flag=true
        this.edittit='新增'

    },
     getadclassList(pagination) {
          this.pagination.current=pagination.current
      this.axios
        .post(
          "suggest/adclassList.php",
          qs.stringify({
            page: this.pagination.current,
            pageSize: pagination.defaultPageSize,
          })
        )
        .then(res => {
          console.log(res);
          if(res.data.code==303){
            this.pagination.total=Number(res.data.result.total)
            for(var i=0;i<res.data.result.data.length;i++){
              res.data.result.data[i].key=i
            }
            this.data=res.data.result.data
          }else{
            this.data=[]
          }
        });
    },
  },
  components: {
    headerComm,
    addggfl
  },
  created() {
    this.getadclassList(this.pagination);

  }
};
</script>

<style lang='less'>
.xw_box {
  position: relative;
  top: 74px;
  text-align: left;
  background: #fff;
  width: 98%;
  left: 15px;
  padding: 20px 10px;
  height: 900px;

  .ant-tabs {
    height: 100%;
  }
}
</style>
